<template>
	<view>
		<view class="direction-box" ref="directionBox">
			<view class="direction" v-for="item in directionData" :key="item.id">
				<!-- <view class="img-box"> -->
					<image src="@/static/1.jpeg" mode="aspectFit" :style="{width: directionBoxWidth / 1.5 + 'px'}"></image>
				<!-- </view> -->
				<view class="direction-name">{{item.name}}</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				directionBoxWidth: 100,
				directionData: [
					{
						id: 0,
						name: '左转',
						image: ''
					}, {
						id: 1,
						name: '直行',
						image: ''
					}, {
						id: 2,
						name: '右转',
						image: ''
					}
				]
			};
		},
		mounted() {
			this.directionBox()
		},
		methods: {
			directionBox() {
				console.log(1111)
				// 注意：想要拿到元素实例，需要在实例已经挂载到页面上才可以
				const query = uni.createSelectorQuery().in(this);
				query.select('.direction-box').boundingClientRect(data => {
					console.log(data.width)
					this.directionBoxWidth = data.width
				}).exec();
				console.log(this.$refs.directionBox)
			}
		}
	}
</script>

<style lang="scss">
	.direction-box {
		width: 100%;
		display: flex;
		
		.direction {
			display: flex;
			justify-content: center;
			align-items: center;
			flex-direction: column;
			border: 3.65upx solid #f00;
		}
	}
</style>
